package com.eternal.framework.binding.viewadapter.image;


import androidx.databinding.BindingAdapter;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

/**
 * @author li
 */
public final class ViewAdapter {
    @BindingAdapter(value = {"url", "placeholderRes"}, requireAll = false)
    public static void setImageUri(ImageView imageView, String url, int placeholderRes) {
        if (!TextUtils.isEmpty(url)) {
            //使用Glide框架加载图片
            Glide.with(imageView.getContext())
                    .load(url)
                    .apply(new RequestOptions().placeholder(placeholderRes))
                    .into(imageView);
        }
    }

    @BindingAdapter(value = {"res"}, requireAll = false)
    public static void setRes(ImageView imageView, int res){
        imageView.setImageResource(res);
        if(res!=0){

//            Glide.with(imageView.getContext())
//                    .load(res)
//                    .apply(new RequestOptions().placeholder(placeholderRes))
//                    .into(imageView);
        }
    }

    @BindingAdapter(value = {"colorFilter"})
    public static void setColorFilter(ImageView imageView, int color){
        imageView.setColorFilter(color);
    }
}

